package com.linkhub.oms.admin.modules.order.domain.param;

import com.linkhub.oms.admin.common.util.EnumValueConstraintUtil.EnumValueConstraint;
import com.linkhub.oms.common.enums.logistic.CountryCodeMappingEnum;
import com.linkhub.oms.common.enums.mp.WarehouseEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName ManualCreateOrderParam
 * @Description: com.linkhub.oms.admin.modules.order.domain.param
 * @Author: Jaycle
 * @CreateDate: 2024/11/20 15:29
 * @Version: 1.0
 */
@Data
public class ManualCreateOrderParam implements Serializable {

    @ApiModelProperty(value = "订单信息", required = true)
    @Valid
    @NotNull(message = "orderInfo cannot be null")
    private OrderInfo orderInfo;

    @ApiModelProperty(value = "地址信息", required = true)
    @Valid
    @NotNull(message = "addressInfo cannot be null")
    private AddressInfo addressInfo;

    @ApiModelProperty(value = "产品信息列表", required = true)
    @NotEmpty(message = "product list cannot be empty")
    @Valid
    private List<ProductInfo> productList;

    @Data
    public static class OrderInfo {
        @ApiModelProperty(value = "系统商店ID", required = true)
        @NotBlank(message = "sysShopId cannot be blank")
        private String sysShopId;

        @ApiModelProperty(value = "平台订单号，最大长度16位，仅支持数字、字母、斜杠", required = true)
        @NotBlank(message = "order number cannot be blank")
        @Pattern(regexp = "^[A-Za-z0-9/]{1,16}$", message = "order number must be alphanumeric and up to 16 characters")
        private String orderNumber;

        @ApiModelProperty(value = "用户邮箱")
        @Email(message = "email must be a valid email address")
        @Size(max = 32, message = "email must not exceed 32 characters")
        private String email;

        @ApiModelProperty(value = "买家指定配送方式")
        @Size(max = 64, message = "shipping method must not exceed 64 characters")
        private String shippingMethod;

        @ApiModelProperty(value = "仓库")
        @Size(max = 64, message = "stash must not exceed 64 characters")
        @EnumValueConstraint(enumClass = WarehouseEnum.class, field = "desc", message = "invalid delivery warehouse")
        private String stash;

        @ApiModelProperty(value = "下单时间", example = "2024-04-19 14:10:25")
        @Pattern(
                regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$|",
                message = "created at must follow the format 'yyyy-MM-dd HH:mm:ss', e.g., 2024-04-19 14:10:25"
        )
        private String createdAt;

        @ApiModelProperty(value = "买家备注")
        @Size(max = 255, message = "buyer note must not exceed 255 characters")
        private String buyerNote;

        @ApiModelProperty(value = "卖家备注")
        @Size(max = 255, message = "seller note must not exceed 255 characters")
        private String sellerNote;

        @ApiModelProperty(value = "商家销售运费")
        @DecimalMin(value = "0.0", message = "freight must be greater than or equal to 0")
        private BigDecimal sellFreight;

        @ApiModelProperty(value = "币种")
        private String currency;
    }

    @Data
    public static class AddressInfo {
        @ApiModelProperty(value = "收件人", required = true)
        @NotBlank(message = "name cannot be blank")
        @Size(max = 64, message = "name must not exceed 64 characters")
        private String name;

        @ApiModelProperty(value = "电话", required = true)
        @NotBlank(message = "phone cannot be blank")
        @Size(max = 32, message = "phone must not exceed 32 characters")
        private String phone;

        @ApiModelProperty(value = "城市", required = true)
        @NotBlank(message = "city cannot be blank")
        @Size(max = 64, message = "city must not exceed 64 characters")
        private String city;

        @ApiModelProperty(value = "邮编", required = true)
        @NotBlank(message = "zip cannot be blank")
        @Size(max = 32, message = "zip must not exceed 32 characters")
        private String zip;

        @ApiModelProperty(value = "省份", required = true)
        @NotBlank(message = "province cannot be blank")
        @Size(max = 200, message = "province must not exceed 200 characters")
        private String province;

        @ApiModelProperty(value = "国家", required = true)
        @NotBlank(message = "country cannot be blank")
        @Size(max = 200, message = "country must not exceed 200 characters")
        private String country;

        @ApiModelProperty(value = "国家简码", required = true)
        @NotBlank(message = "country code cannot be blank")
        @Size(max = 32, message = "country code must not exceed 32 characters")
        @EnumValueConstraint(enumClass = CountryCodeMappingEnum.class, field = "countryCode", message = "invalid country code")
        private String countryCode;

        @ApiModelProperty(value = "地址1", required = true)
        @NotBlank(message = "address1 cannot be blank")
        @Size(max = 255, message = "address1 must not exceed 255 characters")
        private String address1;

        @ApiModelProperty(value = "地址2")
        @Size(max = 255, message = "address2 must not exceed 255 characters")
        private String address2;

        @ApiModelProperty(value = "公司")
        @Size(max = 128, message = "company must not exceed 128 characters")
        private String company;
    }

    @Data
    public static class ProductInfo {
        @ApiModelProperty(value = "平台商品ID", required = true)
        @NotNull(message = "shop product id cannot be null")
        private Long shopProductId;

        @ApiModelProperty(value = "平台商品SKU ID", required = true)
        @NotNull(message = "shop sku id cannot be null")
        private Long shopSkuId;

        @ApiModelProperty(value = "商品单价", required = true)
        @NotNull(message = "price cannot be null")
        @DecimalMin(value = "0.0", message = "price must be greater than or equal to 0")
        private BigDecimal price;

        @ApiModelProperty(value = "商品购买数量", required = true)
        @NotNull(message = "current quantity cannot be null")
        @Min(value = 1, message = "current quantity must be greater than or equal to 1")
        private Integer currentQuantity;

        @ApiModelProperty(value = "商品单价币种", required = true)
        @NotBlank(message = "currency code cannot be blank")
        private String currencyCode;
    }
}